home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / FixMath.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  4.9 KB  |  225 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        FixMath.h
  3.  
  4.      Contains:    Fixed Math Interfaces.
  5.  
  6.      Version:    Technology:    Mac OS 8
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1985-1999 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __FIXMATH__
  18. #define __FIXMATH__
  19.  
  20. #ifndef __MACTYPES__
  21.     #include <MacTypes.h>
  22. #endif
  23.  
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47.  
  48. #define fixed1                ((Fixed) 0x00010000L)
  49. #define fract1                ((Fract) 0x40000000L)
  50. #define positiveInfinity    ((long)  0x7FFFFFFFL)
  51. #define negativeInfinity    ((long)  0x80000000L)
  52. /*
  53.     FixRatio, FixMul, and FixRound were previously in ToolUtils.h
  54. */
  55. EXTERN_API( Fixed )
  56. FixRatio                        (short                     numer,
  57.                                  short                     denom)                                ONEWORDINLINE(0xA869);
  58.  
  59. EXTERN_API( Fixed )
  60. FixMul                            (Fixed                     a,
  61.                                  Fixed                     b)                                    ONEWORDINLINE(0xA868);
  62.  
  63. EXTERN_API( short )
  64. FixRound                        (Fixed                     x)                                    ONEWORDINLINE(0xA86C);
  65.  
  66. EXTERN_API( Fract )
  67. Fix2Frac                        (Fixed                     x)                                    ONEWORDINLINE(0xA841);
  68.  
  69. EXTERN_API( long )
  70. Fix2Long                        (Fixed                     x)                                    ONEWORDINLINE(0xA840);
  71.  
  72. EXTERN_API( Fixed )
  73. Long2Fix                        (long                     x)                                    ONEWORDINLINE(0xA83F);
  74.  
  75. EXTERN_API( Fixed )
  76. Frac2Fix                        (Fract                     x)                                    ONEWORDINLINE(0xA842);
  77.  
  78. EXTERN_API( Fract )
  79. FracMul                            (Fract                     x,
  80.                                  Fract                     y)                                    ONEWORDINLINE(0xA84A);
  81.  
  82. EXTERN_API( Fixed )
  83. FixDiv                            (Fixed                     x,
  84.                                  Fixed                     y)                                    ONEWORDINLINE(0xA84D);
  85.  
  86. EXTERN_API( Fract )
  87. FracDiv                            (Fract                     x,
  88.                                  Fract                     y)                                    ONEWORDINLINE(0xA84B);
  89.  
  90. EXTERN_API( Fract )
  91. FracSqrt                        (Fract                     x)                                    ONEWORDINLINE(0xA849);
  92.  
  93. EXTERN_API( Fract )
  94. FracSin                            (Fixed                     x)                                    ONEWORDINLINE(0xA848);
  95.  
  96. EXTERN_API( Fract )
  97. FracCos                            (Fixed                     x)                                    ONEWORDINLINE(0xA847);
  98.  
  99. EXTERN_API( Fixed )
  100. FixATan2                        (long                     x,
  101.                                  long                     y)                                    ONEWORDINLINE(0xA818);
  102.  
  103. /*
  104.     Frac2X, Fix2X, X2Fix, and X2Frac translate to and from
  105.     the floating point type "extended" (that's what the X is for).
  106.     On the original Mac this was 80-bits and the functions could be
  107.     accessed via A-Traps.  When the 68881 co-processor was added,
  108.     it used 96-bit floating point types, so the A-Traps could not 
  109.     be used.  When PowerPC was added, it used 64-bit floating point
  110.     types, so yet another prototype was added.
  111. */
  112. #if TARGET_CPU_68K
  113. #if TARGET_RT_MAC_68881
  114. EXTERN_API( long double )
  115. Frac2X                            (Fract                     x);
  116.  
  117. EXTERN_API( long double )
  118. Fix2X                            (Fixed                     x);
  119.  
  120. EXTERN_API( Fixed )
  121. X2Fix                            (long double             x);
  122.  
  123. EXTERN_API( Fract )
  124. X2Frac                            (long double             x);
  125.  
  126. #else
  127. EXTERN_API( long double )
  128. Frac2X                            (Fract                     x)                                    ONEWORDINLINE(0xA845);
  129.  
  130. EXTERN_API( long double )
  131. Fix2X                            (Fixed                     x)                                    ONEWORDINLINE(0xA843);
  132.  
  133. EXTERN_API( Fixed )
  134. X2Fix                            (long double             x)                                    ONEWORDINLINE(0xA844);
  135.  
  136. EXTERN_API( Fract )
  137. X2Frac                            (long double             x)                                    ONEWORDINLINE(0xA846);
  138.  
  139. #endif  /* TARGET_RT_MAC_68881 */
  140.  
  141. #else
  142. EXTERN_API( double )
  143. Frac2X                            (Fract                     x);
  144.  
  145. EXTERN_API( double )
  146. Fix2X                            (Fixed                     x);
  147.  
  148. EXTERN_API( Fixed )
  149. X2Fix                            (double                 x);
  150.  
  151. EXTERN_API( Fract )
  152. X2Frac                            (double                 x);
  153.  
  154. #endif  /* TARGET_CPU_68K */
  155.  
  156. /* QuickTime 3.0 makes these Wide routines available on other platforms*/
  157. #if TARGET_CPU_PPC || !TARGET_OS_MAC
  158. EXTERN_API_C( short )
  159. WideCompare                        (const wide *            target,
  160.                                  const wide *            source);
  161.  
  162. EXTERN_API_C( wide *)
  163. WideAdd                            (wide *                    target,
  164.                                  const wide *            source);
  165.  
  166. EXTERN_API_C( wide *)
  167. WideSubtract                    (wide *                    target,
  168.                                  const wide *            source);
  169.  
  170. EXTERN_API_C( wide *)
  171. WideNegate                        (wide *                    target);
  172.  
  173. EXTERN_API_C( wide *)
  174. WideShift                        (wide *                    target,
  175.                                  long                     shift);
  176.  
  177. EXTERN_API_C( unsigned long )
  178. WideSquareRoot                    (const wide *            source);
  179.  
  180. EXTERN_API_C( wide *)
  181. WideMultiply                    (long                     multiplicand,
  182.                                  long                     multiplier,
  183.                                  wide *                    target);
  184.  
  185. /* returns the quotient */
  186. EXTERN_API_C( long )
  187. WideDivide                        (const wide *            dividend,
  188.                                  long                     divisor,
  189.                                  long *                    remainder);
  190.  
  191. /* quotient replaces dividend */
  192. EXTERN_API_C( wide *)
  193. WideWideDivide                    (wide *                    dividend,
  194.                                  long                     divisor,
  195.                                  long *                    remainder);
  196.  
  197. EXTERN_API_C( wide *)
  198. WideBitShift                    (wide *                    src,
  199.                                  long                     shift);
  200.  
  201. #endif  /* TARGET_CPU_PPC || !TARGET_OS_MAC */
  202.  
  203.  
  204.  
  205. #if PRAGMA_STRUCT_ALIGN
  206.     #pragma options align=reset
  207. #elif PRAGMA_STRUCT_PACKPUSH
  208.     #pragma pack(pop)
  209. #elif PRAGMA_STRUCT_PACK
  210.     #pragma pack()
  211. #endif
  212.  
  213. #ifdef PRAGMA_IMPORT_OFF
  214. #pragma import off
  215. #elif PRAGMA_IMPORT
  216. #pragma import reset
  217. #endif
  218.  
  219. #ifdef __cplusplus
  220. }
  221. #endif
  222.  
  223. #endif /* __FIXMATH__ */
  224.  
  225.